/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* swapPairs(struct ListNode* head) {
    if (head == NULL || head->next == NULL)
        return head;
    struct ListNode* newHead = (struct ListNode*)malloc(sizeof(struct ListNode));
    newHead->next = head;
    struct ListNode* cur = head, * prev = newHead;
    while (cur && cur->next)
    {
        struct ListNode* temp = cur->next;
        cur->next = temp->next;
        temp->next = cur;
        prev->next = temp;
        prev = cur;
        cur = cur->next;
    }
    return newHead->next;
}